<?php  namespace Home\Controller;
class CheckoutController extends CommonController
{
	protected $db;
	public function __init(){
		$this->db = new \Common\Model\Site;
	}
	public function index()
	{
		if(!empty($_SESSION['cart']['goods'])){
			$shuju = $_SESSION['cart'];
//			p($shuju);
			View::with('shuju',$shuju);
			$zongjia = Cart::getTotalPrice();
			View::with('zongjia',$zongjia);
		}else{
			$_SESSION['cart']['goods'] = array();
		}
//		p($_SESSION);
//	订单地址添加	
//		p($_SESSION);
		if(IS_POST){
			if(!$this->db->store())
			{
				View::error($this->db->getError());
			}
		}
		$SiteData = $this->db->where('user_did',$_SESSION['yid'])->get();
//		p($SiteData);
		View::with('SiteData',$SiteData);
		View::make();
	}
	public function del()
	{
		$did = Q('get.did',0,'intval');
		$this->db->where('did',$did)->delete();
		go(U('index'));
	}
	public function editajax()
	{
		$did = $_POST['did'];
		$odldata = $this->db->where('did',$did)->first();
		echo json_encode(array('data' => $odldata));
	}
	public function edit()
	{
		$did = Q('get.did',0,'intval');
		$this->db->where('did',$did)->update(array('consignee'=>$_POST['consignee'],'province'=>$_POST['province'],'city'=>$_POST['city'],'district'=>$_POST['district'],'shipping'=>$_POST['shipping'],'postcode'=>$_POST['postcode'],'Phone'=>$_POST['Phone'],'mobile'=>$_POST['mobile']));
		go(u('index'));
	}
	public function morenajax()
	{
		$did = $_POST['did'];
		$this->db->update(array('moren'=>0));
		$this->db->where('did',$did)->update(array('moren'=>1));
		echo 1;
	}
}
